package http

import (
	"bilibi.com/comment/model"
	bm "github.com/bilibili/kratos/pkg/net/http/blademaster"
	"time"
)

func queryComments(c *bm.Context) {
	var err error
	arg := new(model.ArgQueryComment)
	if err = c.Bind(arg); err != nil {
		return
	}
	c.JSON(srv.CommentQuery(c, arg))

}

func listComments(c *bm.Context) {
	var err error
	arg := new(model.ArgList)
	if err = c.Bind(arg); err != nil {
		return
	}
	c.JSON(srv.CommentList(c, arg))

}

func comment(c *bm.Context) {
	var err error
	arg := new(model.ArgID)
	if err = c.Bind(arg); err != nil {
		return
	}
	c.JSON(srv.Comment(c, arg.ID))

}

func addComment(c *bm.Context) {
	var err error
	arg := new(model.AddComment)
	if err = c.Bind(arg); err != nil {
		return
	}

	// 从中间件中获取用户信息
	arg.HubuserID = 1
	arg.ActID = 2

	arg.CreateAt = time.Now()

	c.JSON(nil, srv.AddComment(c, arg))
}

func updateComment(c *bm.Context) {
	var err error
	arg := new(model.UpdateComment)
	if err = c.Bind(arg); err != nil {
		return
	}
	c.JSON(nil, srv.UpdateComment(c, arg))
}

func deleteComment(c *bm.Context) {
	var err error
	arg := new(model.ArgID)
	if err = c.Bind(arg); err != nil {
		return
	}
	c.JSON(nil, srv.DeleteComment(c, arg.ID))
}
